In [1]:
import pandas as pd

Zaida02.PNG IPYNB FILE

In [1]:
df=pd.read_csv(r'lecentralV5.csv',sep=';')
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In [1], line 1
----> 1 df=pd.read_csv(r'lecentralV5.csv',sep=';')

NameError: name 'pd' is not defined
In [3]:
df
Out[3]:
Unnamed: 0 page href model version price dep prof warranty year ... Nombre de propriétaires? : Prime à la conversion? : Prix inclut la batterie : Rechargeable : Autonomie constructeur? : Capacité batterie : Provenance : Voltage batterie : Conso. batterie : Intensité batterie :
0 0 1 https://www.lacentrale.fr/auto-occasion-annonc... MERCEDES CLASSE C 4 SW IV (2) SW 200 D 160 AVANTGARDE LINE 9G-TRONIC 35 180 € 55 Professionnel Garantie 12 mois 2019 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 1 1 https://www.lacentrale.fr/auto-occasion-annonc... JAGUAR XE (2) D200 MHEV AWD R-DYNAMIC SE BVA 54 400 € 60 Professionnel Garantie 24 mois 2020 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2 2 1 https://www.lacentrale.fr/auto-occasion-annonc... FORD FIESTA 6 ACTIVE VI 1.0 ECOBOOST 125 ACTIVE 18 130 € 35 Professionnel Garantie 12 mois 2018 ... 1.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 3 1 https://www.lacentrale.fr/auto-occasion-annonc... CITROEN C1 (2E GENERATION) II 1.0 VTI 72 S&S 4CV FEEL 3P 14 380 € 92 Professionnel Garantie 12 mois 2022 ... 1.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN
4 4 1 https://www.lacentrale.fr/auto-occasion-annonc... NISSAN QASHQAI 2 II (2) 1.6 DCI 130 BUSINESS EDITION XTRONIC 22 780 € 24 Professionnel Garantie 6 mois 2019 ... 1.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
11124 11124 745 https://www.lacentrale.fr/auto-occasion-annonc... MINI MINI 3 CLUBMAN III CLUBMAN 1.5 COOPER 136 KENSINGTON BVA7 28 650 € 14 Professionnel Garantie 24 mois 2019 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
11125 11125 745 https://www.lacentrale.fr/auto-occasion-annonc... SEAT LEON 4 ST IV ST 1.5 ETSI 150 H S&S FR ONE DSG 36 260 € 17 Professionnel Garantie 24 mois 2020 ... NaN NaN oui non NaN NaN NaN 48 V NaN NaN
11126 11126 745 https://www.lacentrale.fr/auto-occasion-annonc... MERCEDES CLASSE A 4 IV 180 D PROGRESSIVE LINE 8G-DCT 38 280 € 31 Professionnel Garantie 24 mois 2022 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
11127 11127 745 https://www.lacentrale.fr/auto-occasion-annonc... SSANGYONG TIVOLI (2) 1.6 E-XDI 136 I LOV IT 21 230 € 30 Professionnel Garantie 12 mois 2019 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
11128 11128 745 https://www.lacentrale.fr/auto-occasion-annonc... BMW SERIE 1 F40 (F40) 118I 140 M SPORT 35 400 € 31 Professionnel Garantie 24 mois 2018 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

11129 rows × 43 columns

In [27]:
df2=df.copy()
In [29]:
df2.dtypes
Out[29]:
Unnamed: 0                          int64
page                                int64
href                               object
model                              object
version                            object
price                              object
dep                                 int64
prof                               object
warranty                           object
year                                int64
km                                 object
Année :                             int64
Boîte de vitesse :                 object
Consommation mixte? :              object
Contrôle technique? :              object
Couleur extérieure :               object
Crit'Air? :                       float64
Garantie :                         object
Garantie constructeur? :           object
Kilométrage compteur? :            object
Mise en circulation :              object
Nombre de places :                float64
Nombre de portes :                float64
Norme Euro? :                      object
Première main (déclaratif)? :      object
Puissance din :                    object
Puissance fiscale :                object
publication                        object
Émissions de CO2? :                object
Énergie :                          object
Couleur intérieure :               object
Puissance moteur :                 object
Vérifié & Garanti? :               object
Nombre de propriétaires? :        float64
Prime à la conversion? :          float64
Prix inclut la batterie :          object
Rechargeable :                     object
Autonomie constructeur? :          object
Capacité batterie :                object
Provenance :                       object
Voltage batterie :                 object
Conso. batterie :                  object
Intensité batterie :               object
dtype: object
In [30]:
#pd.to_numeric(df["price"])
df2['price']=df2['price'].str.replace('€','').str.replace(u'\xa0','').astype("int32")
In [34]:
pd.concat([df.price, df2.price], axis=1)
Out[34]:
price price
0 35 180 € 35180
1 54 400 € 54400
2 18 130 € 18130
3 14 380 € 14380
4 22 780 € 22780
... ... ...
11124 28 650 € 28650
11125 36 260 € 36260
11126 38 280 € 38280
11127 21 230 € 21230
11128 35 400 € 35400

11129 rows × 2 columns

In [36]:
pd.concat([df.price, df2.price], axis=1).dtypes
Out[36]:
price    object
price     int32
dtype: object
In [39]:
df2.km=df2.km.str.replace('km','').str.replace(u'\xa0','').astype("int32")
In [40]:
df2[['km','price']]
Out[40]:
km price
0 67782 35180
1 37323 54400
2 18635 18130
3 6184 14380
4 98560 22780
... ... ...
11124 58621 28650
11125 12733 36260
11126 26387 38280
11127 56661 21230
11128 17825 35400

11129 rows × 2 columns

In [46]:
#df.duplicated(subset='model', keep='first').sum()
df2.pivot_table(columns=['model'], aggfunc='size').sort_values( ascending=False)
Out[46]:
model
PEUGEOT 3008 (2E GENERATION)     433
CITROEN C3 (3E GENERATION)       419
PEUGEOT 308 (2E GENERATION)      258
PEUGEOT 208                      228
PEUGEOT 208 (2E GENERATION)      211
                                ... 
MERCEDES CLASSE E 5 BREAK          1
MERCEDES CLASSE E 5 CABRIOLET      1
MERCEDES CLASSE E 5 COUPE          1
MERCEDES CLASSE G 3 AMG            1
MERCEDES CITAN                     1
Length: 713, dtype: int64
In [49]:
%pip install matplotlib
In [ ]:
 
In [ ]:
 
In [52]:
import matplotlib.pyplot as plt
In [56]:
df_3=df2[df2["model"]=="PEUGEOT 3008 (2E GENERATION)"].sort_values(by='km',ascending=False)
plt.plot(df_3.km,df_3.price)
Out[56]:
[<matplotlib.lines.Line2D at 0x20ff9b83280>]
In [58]:
df_3=df2[df2["model"]=="CITROEN C3 (3E GENERATION)"].sort_values(by='km',ascending=False)
plt.plot(df_3.km,df_3.price)
Out[58]:
[<matplotlib.lines.Line2D at 0x20ff9c7a3d0>]
In [59]:
df_3=df2[df2["model"]=="PEUGEOT 308 (2E GENERATION)"].sort_values(by='km',ascending=False)
plt.plot(df_3.km,df_3.price)
Out[59]:
[<matplotlib.lines.Line2D at 0x20ff9d044c0>]
In [61]:
df_3=df2[df2["model"]=="PEUGEOT 3008 (2E GENERATION)"].sort_values(by='year',ascending=False)
plt.plot(df_3.year,df_3.price)
Out[61]:
[<matplotlib.lines.Line2D at 0x20ff9d80040>]
In [ ]:
 
In [72]:
#df2.columns
df2['Mise en circulation : '].astype('str')
df2['circuilation_date']=pd.to_datetime(df2['Mise en circulation : '], format= "%d/%m/%Y")
#pd.to_datetime(df2['Mise en circulation : ']).dt.date
In [74]:
df_3=df2[df2["model"]=="CITROEN C3 (3E GENERATION)"].sort_values(by='circuilation_date',ascending=False)
plt.plot(df_3['circuilation_date'],df_3.price)
Out[74]:
[<matplotlib.lines.Line2D at 0x20ff9bce2b0>]
In [ ]:
 
In [ ]: